# !/usr/bin/env python
# coding=utf-8
# @Time    : 2018/8/7 12:08
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/rpc_dao.git
# @File    : customer_service.py
# @Software: PyCharm
# @Version: 2.7.5
from db import customer_dao
from utils import my_decorator
from idl_output.ttypes import CustomerInfoDB
from py3_utils import my_thrift


@my_decorator.handle_exception()
def add_customer_info(info):
	return customer_dao.add_customer_info(info)


@my_decorator.handle_exception()
def get_customer_list(owner_id):
	orm_data = customer_dao.get_customer_list(owner_id)
	if not orm_data:
		return None

	thrift_list = []
	for i in orm_data:
		thrift_data = CustomerInfoDB()
		my_thrift.obj_copy_with_same_name(i, thrift_data)
		thrift_list.append(thrift_data)
	return thrift_list


@my_decorator.handle_exception()
def get_customer_info(owner_id, mobile, doc_code, customer_name):
	orm_data = customer_dao.get_customer_info(owner_id, mobile, doc_code, customer_name)
	if not orm_data:
		return None

	thrift_data = CustomerInfoDB()
	my_thrift.obj_copy_with_same_name(orm_data, thrift_data)
	return thrift_data